home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
MACSHELL
/
MS1
/
COMMANDS
/
HEXDUMP.C
< prev
next >
Wrap
Text File
|
1992-12-02
|
7KB
|
284 lines
/*
* MacShell Source File
*
* Copyright (c) 1989, 1990, 1991, 1992 Suick Bay Technologies. All rights reserved.
*
*
* RESTRICTIONS ON MacShell program and source code.
*
* Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
* restricted use by the owner of the CDROM "Disk to the future II".
*
* Ñ╩No permission is granted for any commercial use without the written
* consent of the Suick Bay Technologies.
*
* Ñ╩No permission is granted for any redistribution of any kind use without
* the written consent of the Suick Bay Technologies.
*
* Ñ╩Permission is granted to use this for any personal noncommercial use.
*
* Ñ╩You may not distribute source or executable code at all, nor may you
* distribute it with or within a commercial product without the written
* consent of the Suick Bay Technologies. Please send modifications to
* the author for inclusion in updates to the program. Thanks.
*
*
* MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
* OR ANY PART THEREOF.
*
* In no event will Suick Bay Technologies be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Suick Bay Technologies has been advised of the possibility of such damages.
*
* Suick Bay Technologies can be reached at:
*
* 8768 Cottonwood lane
* Maple Grove, MN 55369
* Voice: (612) 425-7025
* AppleLink: D5233
*
*
* No parts of this software may be reproduced or stored in a
* retrieval system or transmitted in any form, or any means,
* electronic, mechanical, photocopying, recording or otherwise,
* without the prior written permission of Suick Bay Technologies.
*
* Spread the word and not the disk.
*
* SPK 030190 : Fixed file dumps that eof with 0 count
* SPK 022890 : Fixed hex format and added file name printhexData
* SPK 012290 : Initial
*/
#include "SystemPub.h"
#include "Proc.h"
#include "ShellPub.h"
#include "Path.h"
#define BUFSIZE 256
/*******************************************************************
*
* Function HD
*
* Dumps files
*
* PathName Callback function
*
* usage HD [options] [names]
*
*******************************************************************/
#define HDHex (**MyShell).Proc[ProcID].bflags.f0
#define HDInt (**MyShell).Proc[ProcID].bflags.f1
#define HDChar (**MyShell).Proc[ProcID].bflags.f2
#define HDResFork (**MyShell).Proc[ProcID].bflags.f3
#define HDAbort (**MyShell).Proc[ProcID].bflags.f4
void DoDumpLine( WHandle ShellWh, int16 ProcID, int32 index,
int32 count, char *info )
{
int32 *lptr;
int16 *iptr, i;
int16 c;
char buf[ 64 ], asciiData[ 64 ], hexData[ 64 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
*asciiData = '\0';
*hexData = '\0';
if( HDInt )
{
iptr = (int16 *) info;
for( i = 0; i < count/2; i++ )
{
if( HDHex )
sprintf( buf, "%04X ", *iptr );
else
sprintf( buf, "%06d ", *iptr );
strcat( hexData, buf );
*iptr++;
}
}
else
{
lptr = (int32 *) info;
for( i = 0; i < count/4; i++ )
{
if( HDHex )
sprintf( buf, "%08lX ", *lptr );
else
sprintf( buf, "%012ld ", *lptr );
strcat( hexData, buf );
*iptr++;
}
}
if( HDChar )
{
for( i = 0; i < count; i++ )
{
c = info[ i ];
if( !isPrint( c ))
c = '.';
sprintf( buf, "%c", c );
strcat( asciiData, buf );
}
}
if( HDHex )
procPrintf( ShellWh, ProcID, "%8lX : %-40s %s\n", index, hexData, asciiData );
else
procPrintf( ShellWh, ProcID, "%8lX : %-56s %s\n", index, hexData, asciiData );
}
/*******************************************************************/
void HDCallBack( WHandle ShellWh, int16 ProcID, char *path, char *last,
pathType what, int16 vRefNum, int32 dirID )
{
char readBuf[ 64 ], str[ 256 ];
int16 err, fileRefNum;
int32 count, index;
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
if( what == pathIsFile )
{
strcpy( str, last );
CtoPstr( str );
if( HDResFork )
err = HOpenRF( vRefNum, dirID, str, fsRdPerm, &fileRefNum );
else
err = HOpen( vRefNum, dirID, str, fsRdPerm, &fileRefNum );
if( err )
procPrintf( ShellWh, ProcID, "hd : can't dump %s (%d)\n",
last, err );
else
{
procPrintf( ShellWh, ProcID, "hd : %s\n", last );
while( !err && !HDAbort )
{
if( UserAbort() )
HDAbort = TRUE;
err = GetFPos( fileRefNum, &index );
count = 16L;
err = FSRead( fileRefNum, &count, readBuf );
if( (!err || err == eofErr) && count > 0 )
DoDumpLine( ShellWh, ProcID, index, count, readBuf );
}
if( fileRefNum ) /* if a file open, close it */
FSClose( fileRefNum );
}
}
else
procPrintf( ShellWh, ProcID, "hd : %s is not a file.\n", last );
}
/*******************************************************************/
void HDFile( WHandle ShellWh, int16 ProcID, char *argument )
{
ShellWindRec **MyShell;
int16 m;
MyShell = (ShellWindRec **) (**ShellWh).thing;
m = ExpandPath( ShellWh, ProcID, argument, (ProcPtr) HDCallBack,
(**MyShell).pwdVRefNum, (**MyShell).pwdDirID );
ResetShellPWD( ShellWh );
}
/*******************************************************************/
Boolean DoHD( int16 ProcToken, WHandle ShellWh, int16 ProcID, char *string )
{
int16 i, argc;
char *cp, argument[ 256 ];
ShellWindRec **MyShell = (ShellWindRec **) (**ShellWh).thing;
switch( ProcToken )
{
case PROC_INIT :
(**MyShell).Proc[ ProcID ].flags = TRUE;
break;
case PROC_TERM :
case PROC_BREAK :
HDAbort = TRUE;
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
break;
case PROC_STDIN :
if( (**MyShell).Proc[ ProcID ].flags )
{
(**MyShell).Proc[ ProcID ].flags = FALSE;
HDHex = TRUE; /* else decimal */
HDInt = TRUE; /* else longs */
HDChar = TRUE; /* else no chars added */
HDResFork = FALSE;
HDAbort = FALSE;
/* get arguments */
argc = (**MyShell).Proc[ ProcID ].argc;
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
cp = argument;
if( *cp++ == '-' )
while( *cp )
switch( *cp++ )
{
case 'n' : /* */
HDChar = FALSE;
break;
case 'l' : /* */
HDInt = FALSE;
break;
case 'd' : /* */
HDHex = FALSE;
break;
case 'r' : /* */
HDResFork = TRUE;
break;
}
}
for( i = 1; i < argc; i++ )
{
GetArgv( ShellWh, ProcID, i, argument );
if( *argument != '-' )
HDFile( ShellWh, ProcID, argument );
}
/* Tell the shell that we're done */
SendOutToken( ShellWh, ProcID, PROC_BREAK );
/* Turn ourself off */
(**MyShell).Proc[ ProcID ].ProcActive = FALSE;
return( FALSE );
}
}
}